#include <stdio.h>
#include "ofc/DLexer.h"
#include "ofc/DFile.h"

int main(int argc, char *argv[])
{
#ifdef HAVE_DLEXER 
  DLexer *lexer = [DLexer new];
  DFile  *file  = [DFile  new];

  char    name[] = "example.lex";

  if ([file open :name :"r"])
  {
    if ([lexer source :file :name])
    {
      while (![lexer isEof])
      {
        if ([lexer nextExpression :"#[a-z]+"]) // Check and process the possibility of a directive
        {
          printf("Scanned directive:%s\n", [lexer text]);

          [lexer nextLine];            // Skip remaining of the line
        }
        else if ([lexer checkString :"var"])   // Check for string 'var'
        {
          printf("Scanned string:%s\n", [lexer text]);

          [lexer next];                // Set 'var' processed

          [lexer nextWhiteSpace];      // Check and process optional whiteSpace

          [lexer nextExpression :"[.;]"]; // Check and process the optional end of line marker
          
          [lexer nextLine];
        }
        else
        {
          [lexer nextExpression :"."]; // Unexpected, scan first char and ..

          printf("Unexpected data on line:%s\n", [lexer text]); // .. report it

          [lexer nextLine];            // Skip remaining
        }
      }
    }
    else
      printf("Could not start the lexer with \"%s\".\n", name);

    [file close];
  }
  else
    printf("Could not open \"%s\" for scanning:%d\n", name, [file error]);

  [lexer free];                        // Cleanup
  [file  free];
#else
  printf("DLexer is not present in the library.\n");
#endif
  return 0;
}

